import Taro, { Component } from '@tarojs/taro'
import { View } from '@tarojs/components'
import { connect } from '@tarojs/redux'

import {getUserInfo} from '../../actions/userAction'
import UserContent from '../../components/user'

@connect((store) => {
  return {...store.userReducer}
})
class User extends Component{
  config = {
    navigationBarTitleText: '用户中心'
  }
  state = {
    recentlyTopic: [],
    recentlyReply: []
  }
  componentDidMount(){
    getUserInfo({loginname: this.props.loginname}).then(res => {
      this.setState({
        recentlyTopic: res.data.recent_topic,
        recentlyReply: res.data.recent_replies
      })
    })
  }
  render(){
    let {loginname, avatar_url} = this.props
    let {recentlyTopic, recentlyReply} = this.state
    return(
      <View>
        <UserContent 
          loginname={loginname} 
          avatar={avatar_url} 
          recent_topic={recentlyTopic} 
          recent_replies={recentlyReply} 
        />
      </View>
    )
  }
}

export default User